package engine.gui;

import java.util.HashMap;
import engine.game.Manager;

public abstract class ParentObject extends GUIObject{

	private static final long serialVersionUID = 1L;

	private HashMap<String, GUIObject> children ; 

	protected Border border = null  ; 
	
	public ParentObject(Manager m, int x, int y, int w, int h) {
		super(m, x, y, w, h);
		init();
	}

	public ParentObject(Manager m, ParentObject parent){
		super(m, parent); 
	}
	
	public ParentObject(Manager m, ParentObject parent, int w, int h){
		super(m, parent, w, h);
	}

	public void enableBorder(){
		this.border = new Border(this.getManager(), this); 
		this.addNewChild("border", border); 
	}
		
	public void disableBorder(){
		this.remove("border");
		this.border = null ; 
	}
	
	public Border getBorder(){
		return this.border ; 
	}

	public void setBorder(Border border) {
		this.border = border ; 
	}
	
	public void addNewChild(String name, GUIObject o){
		this.children.put(name, o); 
	}
	
	public void remove(String name){
		this.children.remove(name); 
	}
	
	public GUIObject getChildByName(String name){
		return this.children.get(name); 
	}
	
	public HashMap<String, GUIObject> getAllChildren(){
		return this.children; 
	}
	
	@Override
	public void init(){
		super.init();
		this.children = new HashMap<String, GUIObject>(); 
	}

	public void hide(){
		super.hide(); 
		for(GUIObject o: this.children.values())
			o.hide();
	}
	
	public void show(){
		super.show(); 
		for(GUIObject o: this.children.values())
			o.show();
	}
	
	@Override
	public void update() {
		super.update(); 
		if(this.isVisible())
			for(GUIObject o: this.children.values())
				o.update(); 
	}
	
	@Override
	public void render() {
		super.render(); 
//		GL11.glLineWidth(2.0f);
//		Renderer.renderTexturedObject(this, GL11.GL_LINE_LOOP, new Color4f(0.1f, 0.1f, 0.1f, 1.0f));
//		GL11.glLineWidth(1.0f);
		if(this.isVisible())
			for(GUIObject o: this.children.values())
				o.render(); 
	}

	@Override
	public void getInput() {
		super.getInput();
		if(this.isVisible()){ 
			for(GUIObject o: this.children.values())
				o.getInput(); 
		}
	}

	
}
